package com.example.backend.controller;


import com.example.backend.controller.vo.RecentDataVo;
import com.example.backend.mapper.po.HumidityPo;
import com.example.backend.model.ResBean;
import com.example.backend.model.SensorData;
import com.example.backend.service.AirService;
import com.example.backend.service.HumidityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/air", produces = "application/json;charset=UTF-8")
public class AirController {

    private AirService airService;

    @Autowired
    public AirController(AirService airService) {
        this.airService = airService;
    }

    /**
     * 获取最新的湿度数据
     */
    @GetMapping("/latest")
    public ResBean getLatestData() {
        SensorData sensorData = this.airService.getLatestData();
        return new ResBean(sensorData);
    }

    /**
     * 获取一段时间的湿度数据
     */
    @PutMapping("/recent")
    public ResBean getRecentData(@Validated @RequestBody RecentDataVo vo) {
        List<SensorData> dataList = this.airService.getRecentData(vo.getDuration(), vo.getUnit());
        return new ResBean(dataList);
    }

}

